<template>
  <div class="md-user-order-info">
    <div class="r-title">
      <span>Social Data</span>
    </div>
    <div class="user-info-main">
      <div class="main-box">
        <div class="md-panel" v-if="!isExist">
          <div class="avatar">
            <img :src="require('/assets/img/dynamic/avatar.png')" alt="">
          </div>
          <p class="user-name">{{ userInfo.name }}</p>
          <ul class="user-list">
            <li class="user-item">
              <span>E-mail</span>
              <span>{{ userInfo.email }}</span>
            </li>
            <li class="user-item">
              <span>Residence</span>
              <span>{{ userInfo.country }} - {{ userInfo.province }} - {{ userInfo.city }}</span>
            </li>
            <li class="user-item">
              <span>Works</span>
              <span>{{ link }}</span>
            </li>
            <li class="user-item">
              <span>Comfort Zone</span>
              <div>
                <el-tag style="margin-right: 10px" size="small" v-for="item in zones" :key="item.dictValue">{{ item.dictLabel }}</el-tag>
              </div>
            </li>
          </ul>
        </div>
        <div v-else style="text-align: center; margin-top: 40px;">
          <a href="javascript:void(0);" @click="handleApply()">
            <el-link type="primary">Apply Now!</el-link>
          </a>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'MDOrderBaseInfo',
  layout: 'dynamic',
  data () {
    return {
      isExist: true,
      userInfo: {
        country: [],
        works: [{
          link: ''
        }]
      },
      link: '',
      scopesInfo: [],
      zones: []
    }
  },
  created () {
    this.getItemsInfo()
  },
  methods: {
    async getItemsInfo () {
      const res = await this.$axios.get('web/sysDict/type/md_scopes')
      if (res.code == 200) {
        this.scopesInfo = res.data
        this.getInfo()
      }
    },
    async getInfo () {
      const user = this.$local.getItem('user')
      const res = await this.$axios.get(`web/userExperiencer/check/apply/${user.userId}`)
      if (res.code == 200) {
        if (res.data) { // 已经申请过
          this.isExist = false
          this.userInfo = res.data
          this.link = JSON.parse(res.data.works)[0].link
          this.zones = this.scopesInfo.filter(e => {
            return res.data.scopes.split(',').includes(e.dictValue)
          })
        } else { // 没申请跳转到 申请页
          this.isExist = true
        }
      }
    },
    handleApply () {
      let u = `/experiencer/apply?path=${this.$route.path}`
      if (this.$getParamsStr(this.$route.query)) {
        u += `&${this.$getParamsStr(this.$route.query)}`
      }
      this.$router.push(u)
    }
  }
}
</script>
<style lang="scss" scoped>
.md-user-order-info {
  width: 100%;
  .r-title {
    height: 40px;
    line-height: 40px;
    border-bottom: 1px solid #ededed;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #414141;
    padding-right: 20px;
    box-sizing: border-box;
    span {
      font-weight: 100;
      font-size: 24px;
      line-height: 40px;
      border-bottom: 1px solid $md-primary-color;
    }
  }
  .user-info-main {
    margin-top: 20px;
    .md-panel {
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      .avatar {
        width: 100px;
        height: 100px;
        border-radius: 50%;
        overflow: hidden;
        margin-bottom: 20px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .user-name {
        color: $md-primary-color;
        letter-spacing: 2px;
        font-size: 16px;
      }
      .user-list {
        width: 100%;
        .user-item {
          width: 100%;
          padding: 0 20px;
          box-sizing: border-box;
          height: 60px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          border-bottom: 1px solid #dcdcdc;
          span {
            font-size: 14px;
            &:first-child {
              color: #555;
            }
            &:last-child {
              color: #1d1d1d;
            }
          }
        }
      }
    }
  }
}
</style>